package main

import (
	"io"
	"log"
	"net/http"
	"gitee.com/codinglikegosu/gosu/utils"
)

func main() {
    helloHandler := func(w http.ResponseWriter, req *http.Request)  {
        io.WriteString(w, "Hello, gosu!\n")
    }
    http.HandleFunc("/hello", helloHandler)

    // create a no buffer channel, use for tell main thread 
    // server has run.
    done := make(chan struct{})
    
    go func() {
        log.Fatal(http.ListenAndServe(":8080", nil))
    
        // after listen and serve, channel 'done' will be closed.
        close(done)
    }()
    
    // print logo when run it.
    utils.GenerateLogo()

    // receive the channel 'done'.
    // if done is closed, here will block, and run the Server forever;
    // if done is open, here will unlock, the server will be closed.
    <-done
}                      